﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;
using System.ComponentModel;

namespace WorkflowConsoleApplication1
{
    [Designer(typeof(NativeActivitiesContainerDesigner))]
    public sealed class NativeActivitiesContainer : NativeActivity
    {
        internal const string TargetPropertyName = "TargetObject";

        public InArgument<int> Target { get; set; }
        public InArgument<int> Parameters { get; set; }

        public Activity Body { get; set; }

        protected override void Execute(NativeActivityContext context)
        {
            object targetObj = Target.GetLocation(context).Value;
            object parametersObj = Parameters.GetLocation(context).Value;

            context.Properties.Add(TargetPropertyName, (int)targetObj);

            context.ScheduleActivity(Body,OnBodyCompleted);
        }

        protected override void CacheMetadata(NativeActivityMetadata metadata)
        {
            metadata.AddChild(Body);        
            base.CacheMetadata(metadata);
        }

        public void OnBodyCompleted(NativeActivityContext context, ActivityInstance instance)
        {
            Console.WriteLine((instance.Activity as Add).Result.ToString());
        }
    }
}
